package io.renren.modules.avanotes.component;

import io.renren.common.exception.BizCodeEnum;
import io.renren.common.exception.RRException;
import io.renren.config.BizConfig;
import io.renren.modules.avanotes.entity.ReviewScheduleEntity;
import io.renren.modules.avanotes.service.EbbinghausReviewStrategy;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author: xiaomi
 * @date: 2022/2/28
 * @description: 策略模式的 Context
 * 根据不同的参数调用不同的艾宾浩斯策略
 */
@Component
public class EbbinghausReviewContextComponent implements ApplicationContextAware {

    private ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public List<ReviewScheduleEntity> genReviewSchedulesByLevel(Long studyId, Integer ssId, Integer studyDate, Long userId, Integer level) {
        EbbinghausReviewStrategy strategy;
        switch (level) {
            //0-不了解
            case 0:
                strategy = (EbbinghausReviewStrategy) applicationContext.getBean(BizConfig.IMPL_STRANGE_EB);
                break;
            //1-了解
            case 1:
                strategy = (EbbinghausReviewStrategy) applicationContext.getBean(BizConfig.IMPL_ACQUAINTANCE_EB);
                break;
            //2-熟悉
            case 2:
                strategy = (EbbinghausReviewStrategy) applicationContext.getBean(BizConfig.IMPL_FAMILIAR_EB);
                break;
            //3-非常熟悉
            case 3:
                strategy = (EbbinghausReviewStrategy) applicationContext.getBean(BizConfig.IMPL_THOROUGHLY_FAMILIAR_EB);
                break;
            default:
                throw new RRException(BizCodeEnum.EVA_LEVEL_EXECUTE.getMsg());
        }
        List<ReviewScheduleEntity> list = strategy.genReviewSchedules(studyId, ssId, studyDate, userId);
        return list;
    }
}
